<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Title</title>
    <link rel="stylesheet" href="../static/plugins/layui/css/layui.css">
</head>
<style>
    .ok-body {
        padding: 10px
    }
</style>

<body>
<div class="ok-body">

    <div class="layui-row" style="margin-top: 15px">
        <form class="layui-form" action="">

            <!--<label class="layui-form-label">查询条件</label>-->

            <!--<div class="layui-input-inline">-->

                <!--<select id='select'>-->
                    <!--<option value=""></option>-->
                    <!--<option value="name">名称</option>-->
                    <!--<option value="description">描述</option>-->
                <!--</select>-->
            <!--</div>-->

            <!--<div class="layui-input-inline">-->
                <!--<input class="layui-input" id="searchValue" placeholder="根据条件输入合适值" autocomplete="off">-->
            <!--</div>-->


            <!--<button class="layui-btn  layui-btn-normal" style="margin-left: 10px" lay-submit lay-filter="search">搜索-->
            <!--</button>-->

            <button type="button" class="layui-btn layui-btn-warm" id="add" style="float: right">新增</button>

        </form>

    </div>

    <hr class="layui-bg-orange">

    <table class="layui-table layui-form" id="organization" lay-filter="organization"></table>

</div>

<script src="../static/plugins/layui/layui.js"></script>
<script src="../static/js/jquery-3.2.1.min.js"></script>
<script src="../static/js/jquery.base64.js"></script>
<script src="../static/js/device.js"></script>

<script th:inline="none">
    layui.config({
        base: '../static/plugins/layui/lay/modules/'
    }).extend({
        treeTable: 'treeTable'
    });
    var re;
    var treeTable;
    layui.use(['treeTable', 'laypage', 'form'], function () {

        treeTable = layui.treeTable;
        var form = layui.form;

        var tableName = 'organization';
        var tableRenderObject = {
            elem: '#organization'
            , icon_key: 'name'// 必须
            , top_value: 0
            , primary_key: 'id'
            , parent_key: 'parentId'
            ,hide_class: 'layui-hide'
            ,is_checkbox: false
            , icon: {
                open: 'layui-icon layui-icon-triangle-d',
                close: 'layui-icon layui-icon-triangle-r',
                left: 16,
            }
            ,end: function(e){
                form.render();
            }
            , cols: [
                {key: 'name', title: '名称', align: 'center'}
                , {key: 'description', title: '描述', align: 'center'}
                , {key: 'creatorName', title: '创建者', align: 'center'}
                ,{title:'创建日期',align:'center',width:120,template:function (d) {
                        return JJZ.FormatDate(d.gmtCreate,'yyyy-MM-dd');
                    }}
                , {fixed: 'right', title: '操作', align: 'center', template: function (d) {
                        return '<a style="color: #01AAED" href="javascript:JJZ.editPage(\'' + tableName + '\',' + d.id + ')" class="layui-table-link">编辑</a>&nbsp;&nbsp;'+
                            '<a style="color: #01AAED" href="javascript:deleteOrganization(' + d.id + ')" class="layui-table-link">删除</a>';
                    }
                }
            ]
        };

        JJZ.requestTableData(tableName, '', function (data) {
            tableRenderObject.data = data.records;
            re = treeTable.render(tableRenderObject);
        });

        form.on('submit(search)', function (data) {
            var searchCol = $('#select').val();
            var searchValue = $('#searchValue').val();
            var param = 'current=1&pageSize=99999&searchCol=' + searchCol + '&searchValue=' + searchValue;
            JJZ.requestTableData(tableName, param, function (data) {
                re.data = data.records;
                treeTable.render(re);
            });
            return false;
        });

        //新增，跳转至页面
        $('#add').click(function () {
            //先访问一遍判断是否有权限，然后根据具体情况进行处理
            JJZ.ajax('GET', '/' + tableName + '/add', '', function (data) {
                if (JJZ.isJsonString(data)) {
                    //get请求如果返回的内容是json则表示一定出现了错误
                    var json = JSON.parse(data);
                    layer.msg('错误码:' + json.errorCode + ';错误信息:' + json.errorMsg, {icon: 2});
                } else {
                    window.location.href = JJZ.baseUrl + '/' + tableName + '/add';
                }
            })
        });

    });

    function deleteOrganization(id){
        layer.confirm('确认删除？', function (index) {
            JJZ.ajax('POST', '/organization/delete', 'id='+id, function (data) {
                var json = JSON.parse(data);
                if (json.success === false) {
                    layer.msg(json.errorMsg);
                }
                JJZ.requestTableData('organization', '', function (data) {
                    re.data = data.records;
                    treeTable.render(re);
                });
                layer.close(index);
            })
        })
    }

</script>
</body>
</html>